package com.example.rfidserver.consume.subactivity.subactivity_siteconsume;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.rfidserver.R;
import com.example.rfidserver.consume.adapter.SiteConsumeAdapter;
import com.example.rfidserver.dao.ConsumeDao;
import com.example.rfidserver.pojo.Consume;
import com.example.rfidserver.ticket.subactivity.TicketDeleteActivity;
import com.example.rfidserver.utils.DialogHelper;

import java.util.List;

public class DelService extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_del_service);

        ConsumeDao consumeDao = new ConsumeDao();
        List<Consume> services = consumeDao.getConsumeInfo();
        initview(this,services);
    }

    @Override
    protected void onResume() {
        super.onResume();
        ConsumeDao consumeDao = new ConsumeDao();
        List<Consume> services = consumeDao.getConsumeInfo();
        initview(this,services);
    }

    public void initview(Context context, List<Consume> services){
        final ListView mylistview = findViewById(R.id.mylistview_service_del);
        final SiteConsumeAdapter siteConsumeAdapter = new SiteConsumeAdapter(context,services);
        mylistview.setAdapter(siteConsumeAdapter);
        //设置Item项的点击事件
        mylistview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //得到点击的该用户的所有信息
                Consume item_service = siteConsumeAdapter.getItem(position);
                System.out.println(item_service);
                int consume_id = item_service.getConsume_id();
                DialogHelper.commonDialog(DelService.this,"对话框","你要删除服务:"+consume_id+"吗?",item_service);
            }
        });
    }
}
